//
//  LSZMyGospelValueViewController.m
//  JKFuYinProject
//
//  Created by 九酷 on 2018/6/14.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LSZMyGospelValueViewController.h"

@interface LSZMyGospelValueViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    NSArray * array;
}
@property(nonatomic,strong) UITableView * tableViewGospelValues;
@end

@implementation LSZMyGospelValueViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的福音值";
    if(self.isInviteCode == YES){
        array = @[@"签到打卡",@"邀请弟兄姊妹",@"输入邀请码",@"福音值明细",@"兑换提现",@"商城福音值兑换"];
    }else{
        array = @[@"签到打卡",@"邀请弟兄姊妹",@"福音值明细",@"兑换提现",@"商城福音值兑换"];
    }

    [self.tableViewGospelValues registerClass:[LSZMyGospelValuesHeaderCell class] forHeaderFooterViewReuseIdentifier:@"LSZMyGospelValuesHeaderCell"];
    UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:@"领取规则" style:UIBarButtonItemStylePlain target:self action:@selector(onClickedGetTheRules)];
    self.navigationItem.rightBarButtonItem = rightBarItem;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (ScreenWidth == 320) {
        //5
        return 40;
    }else if(ScreenWidth == 375){
        // 6 7
        return 50;
    }else {
        //plus
        return 58;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (ScreenWidth == 320) {
        //5
        return 114;
    }else if(ScreenWidth == 375){
        // 6 7
        return 118;
    }else {
        //plus
        return 122;
    }
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return array.count;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    LSZMyGospelValuesHeaderCell * cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"LSZMyGospelValuesHeaderCell"];
    cell.labelValue.text = self.stringValue;

    CGFloat width = [LSZSpecialPackaging getsTheAdaptiveWidth:cell.labelExplain sizeMaxWidth:ScreenWidth];

    CGRect rect = cell.labelExplain.frame;
    rect.size.width= width;
    rect.origin.x = (ScreenWidth-width)/2;
    cell.labelExplain.frame = rect;

    CGRect rect1 = cell.imageViewPrompt.frame;
    rect1.origin.x = CGRectGetMinX(cell.labelExplain.frame)-cell.imageViewPrompt.frame.size.width;
    cell.imageViewPrompt.frame = rect1;

    return cell;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"%@",array[indexPath.row]];
    cell.textLabel.textColor = titleColorLSZ;
    if (ScreenWidth == 320) {
        //5
        cell.textLabel.font = FONT_(13.5);
    }else if(ScreenWidth == 375){
        // 6 7
        cell.textLabel.font = FONT_(14);
    }else {
        //plus
        cell.textLabel.font = FONT_(14.5);
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        LSZDailyCheckViewController * vc =  [[LSZDailyCheckViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 1){
        Class clz = NSClassFromString(@"LCYaoQingHtmlVC");
        UIViewController *yaoQingHtmlVC = [[clz alloc] init];
        [self.navigationController pushViewController:yaoQingHtmlVC animated:YES];
    }else if (indexPath.row == 2&&self.isInviteCode == YES){
        LSZEnterInvitationCodeViewController * VC = [[LSZEnterInvitationCodeViewController alloc]init];
        [self.navigationController pushViewController:VC animated:YES];
    }else if ((indexPath.row == 3&&self.isInviteCode == YES)||(indexPath.row == 2&&self.isInviteCode == NO)){
        WYWebController *webVC = [WYWebController new];
        webVC.url = [NSString stringWithFormat:@"http://fuyin.app.inping.com/user/incomes?usercode=%@",[_UserM usercode]];
        [self.navigationController pushViewController:webVC animated:YES];
    }else if((indexPath.row == 4&&self.isInviteCode == YES)||(indexPath.row == 3&&self.isInviteCode == NO)){
        LSZExchangeVC * vc = [[LSZExchangeVC alloc]init];
        vc.fuYinValue = self.stringValue;
        [self.navigationController pushViewController:vc animated:YES];
    }else if ((indexPath.row == 5&&self.isInviteCode == YES)||(indexPath.row == 4&&self.isInviteCode == NO)){
        WYWebController *webVC = [WYWebController new];
        NSDate* date = [NSDate dateWithTimeIntervalSinceNow:0];//获取当前时间0秒后的时间
        NSTimeInterval time=[date timeIntervalSince1970]*1000;// *1000 是精确到毫秒，不乘就是精确到秒
        NSString *timeString = [NSString stringWithFormat:@"%.0f", time];
        webVC.url = [NSString stringWithFormat:@"http://fuyin.app.inping.com/user/exchange_fyz?usercode=%@&t=%@",[_UserM usercode],timeString];
        [self.navigationController pushViewController:webVC animated:YES];
    }
    else {

    }
}
-(void)onClickedGetTheRules
{
    WYWebController *webVC = [WYWebController new];
    webVC.url = [NSString stringWithFormat:@"http://fuyin.app.inping.com/user/fyinfo"];
    [self.navigationController pushViewController:webVC animated:YES];
}
-(UITableView *)tableViewGospelValues
{
    if (_tableViewGospelValues == nil) {
        _tableViewGospelValues = [[UITableView alloc]initWithFrame:CGRectMake( 0, 0,ScreenWidth, ScreenHeight) style:UITableViewStyleGrouped];
        _tableViewGospelValues.delegate = self;
        _tableViewGospelValues.dataSource = self;
        _tableViewGospelValues.estimatedRowHeight =0;
        _tableViewGospelValues.estimatedSectionFooterHeight =0;
        _tableViewGospelValues.estimatedSectionHeaderHeight =0;
        _tableViewGospelValues.separatorColor = divider;
        [self.view addSubview:_tableViewGospelValues];
    }
    return _tableViewGospelValues;
}

@end
